package org.carl.grpc.cloud.service.b.service;

import io.grpc.StatusRuntimeException;
import net.devh.boot.grpc.client.inject.GrpcClient;
import org.carl.grpc.cloud.model.demo.HelloReply;
import org.carl.grpc.cloud.model.demo.HelloRequest;
import org.carl.grpc.cloud.model.demo.SimpleGrpc;
import org.springframework.stereotype.Service;

/**
 * email carl.chen@bk.ru
 *
 * @Author: 陈青松
 * @Date: 2019/4/13 0:35
 */
@Service
public class GrpcClientService {

    @GrpcClient("service-a")
    private SimpleGrpc.SimpleBlockingStub simpleStub;

    public String sendMessage(final String name) {
        try {
            final HelloReply response = this.simpleStub.sayHello(HelloRequest.newBuilder().setName(name).build());
            return response.getMessage();
        } catch (final StatusRuntimeException e) {
            return "FAILED with " + e.getStatus().getCode();
        }
    }
}